package core;

public class TextFieldModel {
	
	private boolean numberTyped  = true;

	public TextFieldModel(){ }
	
	public void typed()
	{
		numberTyped = true;
	}
	
	public String readSymbol(String str, char symbol)
	{
		if (numberTyped)
		{
			str = "0";
			numberTyped = false;
		}
		
		int numberOfDigits = str.length();
		if (str.contains("."))
		{
			numberOfDigits--;
		}
		if (str.contains("-"))
		{
			numberOfDigits--;
		}
		switch (symbol)
		{
			case '.':
				if (numberOfDigits >= 10)
				{
					break;
				}
				if (!str.contains("."))
				{
					str += symbol;
				}
				break;
			case '0':
				if (numberOfDigits >= 10)
				{
					break;
				}
				if (!(str.length() == 1 && str.charAt(0) == '0'))
				{
					str += symbol;
				}
				break;
			case 'C':
				str = "0";
				break;
			case 'P':
				str = Double.toString(Math.PI).substring(0, 10);
				numberTyped = true;
			default:
				if (str.length() >= 10)
				{
					break;
				}
				if (str.equals("0"))
				{
					str = "" + symbol;
				}
				else
				{
					str += symbol;
				}
				break;
		}
		return str;
	}

}
